def second_largest(arr: list[int | float]):
    largest = arr[0]
    second = float('-inf')
    for num in arr[1:]:
        if largest < num:
            second = largest
            largest = num
        elif largest > num:
            second = num if num > second else second  
    return second


if __name__ == '__main__':
    print(second_largest([1, 2, 3, 4])) # 3
    print(second_largest([20, 139, 94, 67, 31])) # 94